import QtQuick 2.4
import QtQuick.Controls 2.2
import "buildview"

Item {
    id: item1
    width: 600
    height: 400

    OfflineBaiduMap {
        id: sdoffmap
        width: parent.width + 20
        height: parent.height + 20
    }

    BuildView {
        id: buildView
        objectName: "objsdbuildview"
        width: parent.width + 20
        height: parent.height + 20
        visible: false
    }
    Connections {
        target: buildView
        onUsrBuildClicked: {
            buildView.data[1].clearMapIcon()
            SDController.getFloorDevice(btype, bstrIndex)
        }
    }

    Connections {
        target: SDController
        onSdEvent: {
            buildView.data[1].deviceEvent(isn, event, islt)
            if(!islt)
                SDController.updateSDEmgCntInfo(isn ,event)
        }
        onSdInit: {
            buildView.data[1].createObject(devtype, sdisn, ltisn, port, state,
                                           x, y, power, emgno, emgtime)

        }
    }

    DevRecordPage {
        id: devRecordPage
        visible: false
        anchors.fill: parent
    }

    TabBar {
        id: tabBar
        x: 31
        y: 360
        width: 369
        height: 40
        anchors.bottom: parent.bottom
        anchors.right: parent.right

        TabButton {
            id: tabbtndismap
            text: qsTr("区域地图")
        }

        TabButton {
            id: tabbtnbuildview
            text: qsTr("建筑地图")
        }

        TabButton {
            id: tabbrnrecord
            text: qsTr("设备记录")
        }

        //        TabButton {
        //            id: tabbtntest
        //            text: qsTr("TestBtn")
        //        }
    }

    Connections {
        target: tabbtnbuildview
        onClicked: item1.state = "buildmap"
    }


    //    Connections {
    //        target: tabbtntest
    //        onClicked: sdoffmap.data[1].createmarker(113.948124, 23.026141,
    //                                                 "神山工业城精恒电子茂强办公楼二楼")
    //    }
    Connections {
        target: tabbtndismap
        onClicked: item1.state = ""
    }

    Connections {
        target: tabbrnrecord
        onClicked: item1.state = "staterecord"
    }



    states: [
        State {
            name: "buildmap"

            PropertyChanges {
                target: sdoffmap
                visible: false
            }

            PropertyChanges {
                target: buildView
                visible: true
            }

            PropertyChanges {
                target: devRecordPage
                visible: false
            }
        },
        State {
            name: "staterecord"
            PropertyChanges {
                target: sdoffmap
                visible: false
            }

            PropertyChanges {
                target: buildView
                visible: false
            }

            PropertyChanges {
                target: devRecordPage
                visible: true
                opacity: 1
            }
        }
    ]
}
